package com.xiangyang.pos.bean;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.xiangyang.pos.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by NEGIER on 2017/9/11.
 */

public class BLEListAdapter extends BaseAdapter {
    private List<BLEItem> lists=new ArrayList<>();
    private LayoutInflater mInflater;

    public BLEListAdapter(Context context , List<BLEItem> lists) {
        mInflater = LayoutInflater.from(context);
        this.lists=lists;
    }

    @Override
    public int getCount() {
        return lists.size();
    }

    @Override
    public Object getItem(int position) {
        return lists.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(convertView == null) {
            holder = new ViewHolder();
            convertView = mInflater.inflate(R.layout.item_ble,null);
            holder.tvName = (TextView)convertView.findViewById(R.id.tv_name);
            holder.tvMac = (TextView)convertView.findViewById(R.id.tv_mac);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder)convertView.getTag();
        }
        BLEItem item = (BLEItem)getItem(position);
        holder.tvName.setText(item.getName());
        holder.tvMac.setText(item.getMac());
        return convertView;
    }
    static class ViewHolder
    {
        public TextView tvName;
        public TextView tvMac;
    }
}
